/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ui;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

/**
 *
 * @author tho.hoang
 */
public class GridItem extends AGridItem {

    public GridItem(String id, Image image, String text) {
        super(image, text);
        super.id = id;
    }

    public int getWidth() {
        int iw = 0, tw = 0;
        if (image != null) {
            iw = image.getWidth() + style.getPadding().getLeftAndRight();
        }
        if (text != null && text.length() > 0 && font != null) {
//            tw = boldFont.stringWidth(text) + style.getPadding().getLeftAndRight();
            tw = font.getFontBold().stringWidth(text) + style.getPadding().getLeftAndRight();
        }

        return (iw > tw) ? iw : tw;
    }

    public int getHeight() {
        int ih = 0, th = 0;
        if (image != null) {
            ih = image.getHeight() + style.getPadding().getTopAndBottom();
        }
        if (text != null && text.length() > 0 && font != null) {
            th = font.getFontBold().getHeight() + style.getPadding().getTopAndBottom();
            th += style.getRowHeight();
        }

        return ih + th;
    }

    public void paint(int x, int y, Graphics g, boolean validate) {
        if (validate && !isSelectedPaint(x, y)) {
            return;
        }
        g.setColor(focus == true ? style.getSelectedBgColor() : style.getBgColor());
        g.fillRoundRect(x, y, getMaxWidth(), getMaxHeight(), 20, 20);
        int l = x + (getWidth() - image.getWidth()) / 2;
        int t = y + (getHeight() - image.getHeight()) / 2;
        g.drawImage(image, l, t, Graphics.TOP | Graphics.LEFT);
    }
}
